package com.zy.cat.common.utils;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.pdd.pop.sdk.common.util.JsonUtil;
import com.pdd.pop.sdk.http.PopClient;
import com.pdd.pop.sdk.http.PopHttpClient;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkMallUrlGenRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkMemberAuthorityQueryRequest;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkMallUrlGenResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkMemberAuthorityQueryResponse;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkCmsPromUrlGenerateRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkGoodsDetailRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkGoodsPromotionUrlGenerateRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkGoodsSearchRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkLotteryUrlGenRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkOrderDetailGetRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkOrderListIncrementGetRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkResourceUrlGenRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkRpPromUrlGenerateRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkThemeListGetRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkThemePromUrlGenerateRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkTopGoodsListQueryRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkWeappQrcodeUrlGenRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsCatsGetRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsOptGetRequest;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkCmsPromUrlGenerateResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkGoodsDetailResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkGoodsPromotionUrlGenerateResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkGoodsSearchResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkLotteryUrlGenResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkOrderDetailGetResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkOrderListIncrementGetResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkResourceUrlGenResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkRpPromUrlGenerateResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkThemeListGetResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkThemePromUrlGenerateResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsCatsGetResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsOptGetResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkTopGoodsListQueryResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkWeappQrcodeUrlGenResponse;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @info 拼多多开放API
 * @author Link
 * @date 2019-09-05 13:54
 */
@Slf4j
public class PDDAPI {
	private String clientId = "cc06974ff24c4ed695d9fb0f2dc6efb7";
	private String pid = "10740642_144496213";
	private String clientSecret = "f18d48bdbbf7be84fa1ef4e530357991e14cd0af";

	private PDDAPI(String client_id, String client_secret, String pid) {
		super();
		this.clientId = client_id;
		this.clientSecret = client_secret;
		this.pid = pid;
	}

	/**
	 * 
	 * @info 拼多多接口
	 * @author Link
	 * @date 2019-09-03 14:45
	 * @param type 0.微信小程序、1.九趣猫
	 * @param ctype (仅type=1时生效)APP平台(0.九趣猫、1.淘淘集、2.一陶)
	 * @return
	 */
	public static PDDAPI getInstance(int type,int ctype) {
		String pid = "9096250_117881715";
		String client_id = "c891f3601e044c3696f695a62fe5ca18";
		String client_secret = "8173fdab260d8e3c0093b30c6d81c1733bc304e0";
		if (type == 1) {
			client_id = "cc06974ff24c4ed695d9fb0f2dc6efb7";
			client_secret = "f18d48bdbbf7be84fa1ef4e530357991e14cd0af";
			
			if(ctype==0) {
				pid = "10740642_144496213";
			}else if(ctype==1) {
				pid = "10740642_145710730";
			}else if(ctype==2) {
				pid = "10740642_145711740";
			}
		}
		return new PDDAPI(client_id, client_secret, pid);
	}

	/**
	 * 
	 * @info 获取全部类目信息
	 * @author Link
	 * @date 2019-09-03 15:05
	 * @param cat_id
	 * @return
	 */
	public PddGoodsCatsGetResponse getshopCats(long cat_id) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddGoodsCatsGetRequest request = new PddGoodsCatsGetRequest();
		request.setParentCatId(cat_id);
		PddGoodsCatsGetResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			return null;
		}
		log.info(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 获取指定频道商城CMS链接
	 * @author Link
	 * @date 2019-09-04 14:48
	 * @param channelType
	 * @param custom_parameters
	 * @return
	 */
	public PddDdkCmsPromUrlGenerateResponse getshopCMS(int channelType, String custom_parameters) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkCmsPromUrlGenerateRequest request = new PddDdkCmsPromUrlGenerateRequest();
		/* 是否生成短链接，true-是，false-否 */
		request.setGenerateShortUrl(true);
		/* 是否生成手机跳转链接。true-是，false-否，默认false */
		request.setGenerateMobile(true);
		/* 单人团多人团标志。true-多人团，false-单人团 默认false */
		request.setMultiGroup(true);
		/* 自定义参数，为链接打上自定义标签。自定义参数最长限制64个字节。 */
		request.setCustomParameters(custom_parameters);
		/* 是否唤起微信客户端， 默认false 否，true 是 */
		request.setGenerateWeappWebview(false);
		/* 0, "1.9包邮"；1, "今日爆款"； 2, "品牌清仓"； 4,"PC端专属商城" */
		request.setChannelType(channelType);
		List<String> pIdList = new ArrayList<String>();
		pIdList.add(pid);
		request.setPIdList(pIdList);
		PddDdkCmsPromUrlGenerateResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 获取商品列表
	 * @author Link
	 * @date 2019-09-03 18:01
	 * @param query             搜索词
	 * @param page              页码
	 * @param pageSize          每页N条
	 * @param sortType          排序类型
	 * @param cat_id            类目ID（0.全部）
	 * @param custom_parameters 渠道自定义参数 == 淘宝的relationId
	 * @return
	 */
	public PddDdkGoodsSearchResponse getshops(String pid,String query, int page, int pageSize, int sortType, long cat_id,
			long optId, boolean withCoupon) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkGoodsSearchRequest request = new PddDdkGoodsSearchRequest();
		if (StringUtils.isNotBlank(pid)) {
			request.setCustomParameters(" {\"uid\":\""+pid+"\"}");
		}
		if (StringUtils.isNotBlank(query)) {
			request.setKeyword(query);
		}
		if (optId >= 0) {
			request.setOptId(optId);
		}
		request.setPage(page);
		request.setPageSize(pageSize);
		request.setSortType(sortType);
		request.setWithCoupon(withCoupon);
		request.setPid(this.pid);
//        request.setRangeList("str");
		if (cat_id >= 0) {
			request.setCatId(cat_id);
		}
//        List<Long> goodsIdList = new ArrayList<Long>();
//        goodsIdList.add(0L);
//        request.setGoodsIdList(goodsIdList);
//        request.setMerchantType(0);
//		request.setPid(this.pid);
//		request.setCustomParameters(custom_parameters);
//        List<Integer> merchantTypeList = new ArrayList<Integer>();
//        merchantTypeList.add(0);
//        request.setMerchantTypeList(merchantTypeList);
//		request.setIsBrandGoods(false);
		PddDdkGoodsSearchResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			return null;
		}
		log.info(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 获取商品详情
	 * @author Link
	 * @date 2019-09-05 10:46
	 * @param goodsId
	 * @return
	 */
	public PddDdkGoodsDetailResponse getshopsInfo(long goodsId) {

		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkGoodsDetailRequest request = new PddDdkGoodsDetailRequest();
		List<Long> goodsIdList = new ArrayList<Long>();
		goodsIdList.add(goodsId);
		request.setGoodsIdList(goodsIdList);
//	    request.setPid(this.pid);
//	    request.setCustomParameters(custom_parameters);
//	    request.setZsDuoId(0L);
//	    request.setPlanType(0);
		PddDdkGoodsDetailResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
//		List<GoodsDetailResponseGoodsDetailsItem> sdf=response.getGoodsDetailResponse().getGoodsDetails();
//		log.info(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 获取时间段内的订单数据（最大时间间隔1天）
	 * @author Link
	 * @date 2019-09-04 14:47
	 * @param stime
	 * @param etime
	 */
	public PddDdkOrderListIncrementGetResponse getOrder(long stime, long etime, int page, int pageSize) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkOrderListIncrementGetRequest request = new PddDdkOrderListIncrementGetRequest();
		request.setStartUpdateTime(stime);
		request.setEndUpdateTime(etime);
		request.setPageSize(pageSize < 1 ? 300 : pageSize);
		request.setPage(page < 1 ? 1 : page);
		request.setReturnCount(true);
		PddDdkOrderListIncrementGetResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info("-拼多多订单-->" + JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 填单获取商品详情
	 * @author Link
	 * @date 2019-09-04 14:46
	 * @param orderId
	 */
	public PddDdkOrderDetailGetResponse getOrderInfo(String orderId) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkOrderDetailGetRequest request = new PddDdkOrderDetailGetRequest();
		request.setOrderSn(orderId);
		PddDdkOrderDetailGetResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 商品高佣转链
	 * @author Link
	 * @date 2019-09-04 18:09
	 * @param goodsId           商品ID
	 * @param shortUrl          是否生成短链接，true-是，false-否
	 * @param multiGroup        true--生成多人团推广链接
	 *                          false--生成单人团推广链接（默认false）1、单人团推广链接：用户访问单人团推广链接，可直接购买商品无需拼团。2、多人团推广链接：用户访问双人团推广链接开团，若用户分享给他人参团，则开团者和参团者的佣金均结算给推手
	 * @param custom_parameters 订单标识
	 * @param weappWebview      是否生成唤起微信客户端链接，true-是，false-否，默认false
	 * @param WeApp             是否生成小程序推广
	 * @param WeBo              是否生成微博推广链接
	 * @return
	 */
	public PddDdkGoodsPromotionUrlGenerateResponse getShopConvert(long goodsId, boolean shortUrl, boolean multiGroup,
			String custom_parameters, boolean weappWebview, boolean WeApp, boolean WeBo) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkGoodsPromotionUrlGenerateRequest request = new PddDdkGoodsPromotionUrlGenerateRequest();
		request.setPId(this.pid);
		List<Long> goodsIdList = new ArrayList<Long>();
		goodsIdList.add(goodsId);
		request.setGoodsIdList(goodsIdList);
		request.setGenerateShortUrl(shortUrl);
		request.setMultiGroup(multiGroup);
		request.setCustomParameters(custom_parameters);
		request.setGenerateWeappWebview(weappWebview);
		request.setZsDuoId(0L);
		request.setGenerateWeApp(WeApp);
		request.setGenerateWeiboappWebview(WeBo);
		PddDdkGoodsPromotionUrlGenerateResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return response;
	}

//	/**
//	 * 
//	 * @info 链接高佣转链
//	 * @author Link
//	 * @date 2019-10-29 17:43
//	 * @param url
//	 * @return
//	 */
//	public PddDdkGoodsZsUnitUrlGenResponse getUrlConvert( String url, ) {
//		PopClient client = new PopHttpClient(clientId, clientSecret);
//
//		PddDdkGoodsZsUnitUrlGenRequest request = new PddDdkGoodsZsUnitUrlGenRequest();
//        request.setSourceUrl("str");
//        request.setPid("str");
//        PddDdkGoodsZsUnitUrlGenResponse response = null;
//        log.info(JSON.toJSONString(response));
//		try {
//			response = client.syncInvoke(request);
//		} catch (Exception e) {
//			return null;
//		}
//		return response;
//	}

	/**
	 * 
	 * @info 获取商品主题高佣转链
	 * @author Link
	 * @date 2019-10-31 15:35
	 * @param upid
	 * @param tids
	 * @return
	 */
	public PddDdkThemePromUrlGenerateResponse getThemeShop(String upid, Long... tids) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkThemePromUrlGenerateRequest request = new PddDdkThemePromUrlGenerateRequest();
		request.setPid(this.pid);

		/* 主题ID列表,例如[1,235] */
		request.setThemeIdList(Arrays.asList(tids));
		/* 是否生成短链接,true-是,false-否 */
		request.setGenerateShortUrl(true);

		/* 是否生成手机跳转链接。true-是,false-否,默认false */
		request.setGenerateMobile(false);

		/* 自定义参数,为链接打上自定义标签。自定义参数最长限制64个字节。 */
		request.setCustomParameters(upid);

		/* 是否唤起微信客户端， 默认false 否，true 是 */
		request.setGenerateWeappWebview(false);

		/* 是否生成小程序链接 */
		request.setGenerateWeApp(true);

		/* 是否返回 schema URL */
		request.setGenerateSchemaUrl(false);

		/* 是否生成qq小程序 */
		request.setGenerateQqApp(false);

		// 异步调用
		Future<PddDdkThemePromUrlGenerateResponse> futureResponse = null;
		try {
			futureResponse = client.asyncInvoke(request);
		} catch (Exception e1) {
			return null;
		}
		try {
		} catch (Exception e) {
			return null;
		}
		try {
			return futureResponse.get();
		} catch (InterruptedException e) {
			return null;
		} catch (ExecutionException e) {
			return null;
		}
	}

	/**
	 * 
	 * @info 多多进宝主题列表查询
	 * @author Link
	 * @return
	 * @date 2019-10-29 17:58
	 */
	public PddDdkThemeListGetResponse themeList() {

		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkThemeListGetRequest request = new PddDdkThemeListGetRequest();
		/* pageSize的取值范围是1-50 */
		request.setPageSize(50);
		/* page的取值范围是1-10000！ */
		request.setPage(1);
		PddDdkThemeListGetResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 获取商品标签
	 * @author Link
	 * @date 2019-09-05 09:27
	 * @param optId
	 * @return
	 */
	public PddGoodsOptGetResponse getShopOpts(int optId) {

		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddGoodsOptGetRequest request = new PddGoodsOptGetRequest();
		request.setParentOptId(optId);
		PddGoodsOptGetResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 获取商品标签-->无权限
	 * @author Link
	 * @date 2019-09-05 09:27
	 * @param optId
	 * @return
	 */
	public PddDdkWeappQrcodeUrlGenResponse getShopQrcode(String upid, long goodsId) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkWeappQrcodeUrlGenRequest request = new PddDdkWeappQrcodeUrlGenRequest();
		request.setPId(this.pid);
		List<Long> goodsIdList = new ArrayList<Long>();
		goodsIdList.add(goodsId);

		/* 商品ID */
		request.setGoodsIdList(goodsIdList);

		/* 自定义参数，为链接打上自定义标签。自定义参数最长限制64个字节。 */
		request.setCustomParameters(upid);

		/* 招商多多客ID */
		request.setZsDuoId(0L);

		/* 是否生成店铺收藏券推广链接 */
		request.setGenerateMallCollectCoupon(false);

		/*  */
		PddDdkWeappQrcodeUrlGenResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 多多客获取爆款排行商品接口
	 * @author Link
	 * @date 2019-11-01 08:58
	 * @param sortType
	 */

	/**
	 * 
	 * @info 多多客获取爆款排行商品接口
	 * @author Link
	 * @param pid 
	 * @date 2019-11-01 10:48
	 * @param sortType 1-实时热销榜；2-实时收益榜
	 * @param page     页码
	 * @return
	 */
	public PddDdkTopGoodsListQueryResponse getTopShops(String pid, int sortType, int page) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkTopGoodsListQueryRequest request = new PddDdkTopGoodsListQueryRequest();
		if (StringUtils.isNotBlank(pid)) {
			request.setCustomParameters(pid);
		}
		page = page < 1 ? 1 : page;

		/* 推广位id */
		request.setPId(this.pid);

		/* 从多少位置开始请求；默认值 ： 0，offset需是limit的整数倍，仅支持整页翻页 */
		request.setOffset((page - 1) * 50);

		/* 1-实时热销榜；2-实时收益榜 */
		request.setSortType(sortType);

		/* 请求数量；默认值 ： 400 */
		request.setLimit(50);

		PddDdkTopGoodsListQueryResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 多多客生成转盘抽免单url
	 * @author Link
	 * @date 2019-11-01 16:31
	 * @return
	 */
	public PddDdkLotteryUrlGenResponse getLotteryUrl(String upid) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkLotteryUrlGenRequest request = new PddDdkLotteryUrlGenRequest();
		List<String> pidList = new ArrayList<String>();
		pidList.add(this.pid);
		request.setPidList(pidList);
		/* 是否生成唤起微信客户端链接，true-是，false-否，默认false */
		request.setGenerateWeappWebview(false);

		/* 是否生成短链接，true-是，false-否 */
		request.setGenerateShortUrl(true);

		/*
		 * true--生成多人团推广链接
		 * false--生成单人团推广链接（默认false）1、单人团推广链接：用户访问单人团推广链接，可直接购买商品无需拼团。2、多人团推广链接：
		 * 用户访问双人团推广链接开团，若用户分享给他人参团，则开团者和参团者的佣金均结算给推手
		 */
		request.setMultiGroup(true);

		/* 自定义参数，为链接打上自定义标签。自定义参数最长限制64个字节。 */
		request.setCustomParameters(upid);

		/* 是否生成大转盘和主题的小程序推广链接 */
		request.setGenerateWeApp(true);

		/* 是否返回 schema URL */
		request.setGenerateSchemaUrl(false);

		/* 是否生成qq小程序 */
		request.setGenerateQqApp(false);

		PddDdkLotteryUrlGenResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(JSON.toJSONString(response));
		return response;
	}

	/**
	 * 
	 * @info 拼多多频道推广
	 * @author Link
	 * @date 2019-11-01 17:08
	 * @param upid  用户标识
	 * @param rtype 频道来源：4-限时秒杀,39997-充值中心, 39998-转链type，39999-电器城，39996-百亿补贴
	 * @param surl  原链接（rtype=39998使用）
	 */
	public PddDdkResourceUrlGenResponse getResourceUrl(String upid, int rtype) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkResourceUrlGenRequest request = new PddDdkResourceUrlGenRequest();

		/* 自定义参数，为链接打上自定义标签。自定义参数最长限制64个字节 */
		request.setCustomParameters(upid);

		/* 是否生成小程序 */
		request.setGenerateWeApp(true);

		/* 推广位 */
		request.setPid(this.pid);

		/* 频道来源：4-限时秒杀,39997-充值中心, 39998-转链type，39999-电器城，39996-百亿补贴 */
		request.setResourceType(rtype);

		/* 原链接 */
//	        request.setUrl(surl);

		/* 是否返回 schema URLL */
		request.setGenerateSchemaUrl(false);

		/* 是否生成qq小程序 */
		request.setGenerateQqApp(false);
		PddDdkResourceUrlGenResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			return null;
		}
		System.out.println("resourceUrl-->" + JSON.toJSONString(response));
		return response;
	}

	public PddDdkMallUrlGenResponse getMallConvert(String upid, long mid) {

		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkMallUrlGenRequest request = new PddDdkMallUrlGenRequest();
		/*
		 * 自定义参数，为链接打上自定义标签；自定义参数最长限制64个字节；格式为： {"uid":"11111","sid":"22222"} ，其中 uid
		 * 用户唯一标识，可自行加密后传入，每个用户仅且对应一个标识，必填； sid
		 * 上下文信息标识，例如sessionId等，非必填。该json字符串中也可以加入其他自定义的key
		 */
		request.setCustomParameters(upid);
		/* 是否生成店铺收藏券推广链接 */
		request.setGenerateMallCollectCoupon(true);
		/* 是否生成qq小程序 */
		request.setGenerateQqApp(true);
		/* 是否返回 schema URL */
		request.setGenerateSchemaUrl(true);
		/* 是否生成短链接，true-是，false-否 */
		request.setGenerateShortUrl(true);
		/* 是否生成唤起微信客户端链接，true-是，false-否，默认false */
		request.setGenerateWeappWebview(true);
		/* 店铺id */
		request.setMallId(mid);
		/*
		 * true--生成多人团推广链接
		 * false--生成单人团推广链接（默认false）1、单人团推广链接：用户访问单人团推广链接，可直接购买商品无需拼团。2、多人团推广链接：
		 * 用户访问双人团推广链接开团，若用户分享给他人参团，则开团者和参团者的佣金均结算给推手
		 */
		request.setMultiGroup(true);
		/* 推广位 */
		request.setPid(this.pid);
		PddDdkMallUrlGenResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info(JsonUtil.transferToJson(response));
		return response;
//		PddDdkOauthMallUrlGenRequest request = new PddDdkOauthMallUrlGenRequest();
//        request.setMallId(mid);
//        request.setPid(this.pid);
//        request.setGenerateWeappWebview(false);
//        request.setGenerateShortUrl(true);
//        request.setMultiGroup(true);
//        request.setCustomParameters(upid);
//        request.setGenerateMallCollectCoupon(false);
//        request.setGenerateSchemaUrl(false);
//        request.setGenerateQqApp(false);
//        PddDdkOauthMallUrlGenResponse response = null;
//		try {
//			response = client.syncInvoke(request,access_token);
//		} catch (Exception e) {
//			log.error("-getMallConvert-ERROR-->"+e.getLocalizedMessage());
//			return null;
//		}
//        System.out.println("-getMallConvert-->"+JSON.toJSONString(response));
//		return response;
	}

	/**
	 * 
	 * @info 生成备案信息
	 * @author Link
	 * @date 2020-08-17 16:11
	 * @param mate
	 * @param date
	 * @return
	 */
	public PddDdkRpPromUrlGenerateResponse getBeiAnUrl(String spid, String customer) {
		PopClient client = new PopHttpClient(clientId, clientSecret);

		PddDdkRpPromUrlGenerateRequest request = new PddDdkRpPromUrlGenerateRequest();
		request.setChannelType(10);
		request.setCustomParameters(customer);
		if (StringUtils.isBlank(spid)) {
			spid = pid;
		}
		
		request.setPIdList(Arrays.asList(spid));
		request.setCustomParameters(customer);
		PddDdkRpPromUrlGenerateResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("-setBeiAnInfo-->"+JsonUtil.transferToJson(response));
		return response;
	}

	/**
	 * 查看备案是否成功
	 * @info 
	 * @author Link
	 * @date 2020-08-18 10:13
	 * @param spid
	 * @param customer
	 * @return
	 */
	public PddDdkMemberAuthorityQueryResponse getBeiAnInfo(String spid, String customer) {
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkMemberAuthorityQueryRequest request = new PddDdkMemberAuthorityQueryRequest();
		if (StringUtils.isBlank(spid)) {
			spid = pid;
		}
		request.setPid(spid);
		request.setCustomParameters(customer);
		PddDdkMemberAuthorityQueryResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(JsonUtil.transferToJson(response));
		response.getAuthorityQueryResponse().getBind();
		return response;
	}

	public static void main(String[] args) {
//		long stime = LocalDateTime.now().minusDays(1).minusHours(3).toEpochSecond(ZoneOffset.of("+8"));
//		long etime = LocalDateTime.now().minusHours(10).plusMinutes(1).toEpochSecond(ZoneOffset.of("+8"));
		
		long stime = LocalDateTime.now().minusHours(1).toEpochSecond(ZoneOffset.of("+8"));
		long etime = LocalDateTime.now().plusMinutes(1).toEpochSecond(ZoneOffset.of("+8"));

//		PDDAPI.getInstance(1,0).getOrder(stime, etime, 1, 10);
		
		getInstance(1, 1).getshops("4044516811", "鞋子", 1, 30, 0, 0, 0, false);

	}

	/**
	 * 获取今日推荐商品
	 * @param sid
	 * @param pageNum
	 * @param pageSize
	 * @param sorttype
	 * @param withCoupon
	 * @return
	 */
	public PddDdkGoodsSearchResponse getTjshops(Long sid, int pageNum, int pageSize, Integer sorttype,
			boolean withCoupon) {
		// TODO Auto-generated method stub
		PopClient client = new PopHttpClient(clientId, clientSecret);
		PddDdkGoodsSearchRequest request=new PddDdkGoodsSearchRequest();
		request.setPage(pageNum);
		request.setPageSize(pageSize);
		request.setSortType(sorttype);
		request.setWithCoupon(withCoupon);
		List<Long> goodsIdList = new ArrayList<Long>();
		goodsIdList.add(sid);
	
		PddDdkGoodsSearchResponse response = null;
		try {
			response = client.syncInvoke(request);
		} catch (Exception e) {
			return null;
		}
		log.info(JSON.toJSONString(response));
		return response;
	}
}
